package org.jradweb.core.orm;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;

/**
 * Generic DAO (Data Access Object) with common methods to CRUD POJOs.
 *
 * <p>Extend this interface if you want typesafe (no casting necessary) DAO's for your
 * domain objects.
 * 
 * Created On 2007-10-20
 *
 * @author <a href="mailto:wagzhi@gmail.com">Paul Wang</a>
 * @version $Id: GenericDao.java 149 2008-10-10 03:10:10Z wagzhi $
 * @param <T> a type variable
 * @param <PK> the primary key for that type
 */
public interface GenericDao <T, PK extends Serializable> {

	/**
	 * Make a transient instance persistent. This operation cascades to associated
	 * instances if the association is mapped with <tt>cascade="persist"</tt>.<br>
	 * <br>
	 * The semantics of this method are defined by JSR-220.
	 *
	 * @see org.hibernate.Session#persist(Object)
	 * @param object a transient instance to be made persistent
	 */
	public abstract void persist(T object);
	/**
	 * Either {@link #save(Object)} or {@link #update(Object)} the given
	 * instance, depending upon resolution of the unsaved-value checks (see the
	 * manual for discussion of unsaved-value checking).
	 * <p/>
	 * This operation cascades to associated instances if the association is mapped
	 * with <tt>cascade="save-update"</tt>.
	 * 
	 * @see org.hibernate.Session#saveOrUpdate(Object)
	 * @param object a transient or detached instance containing new or updated state
	 */
	public abstract void attachDirty(T object);
	/**
	 * Simply reassociate a transient instance
	 * with a session (<tt>LockMode.NONE</tt>). This operation cascades to associated
	 * instances if the association is mapped with <tt>cascade="lock"</tt>.
	 * 
	 * @see org.hibernate.Session#saveOrUpdate(Object,LockeMode)
	 * @param object a persistent or transient instance
	 * @throws HibernateException
	 */
	public abstract void attachClean(T object);

	public abstract void delete(T object);

	public abstract T merge(T Object);

	public abstract T findById(PK id);

	public abstract List<T> findByExample(T instance);

	public T getUniqueResultByCondition(String condition,Map<String,Object> params);

	public List<T> getPage(int pageNumber,int pageSize);
	
	public List<T> getPage(int pageNumber, int pageSize, String condition, Map<String,Object> params);

	public int getPageCount(int pageSize, String condition, Map<String,Object> params);

	public long getTotalCount();
	/**
	 * get count by hql condition
	 * @param condition
	 * @param params
	 * @return
	 */
	public long getCountByCondition(String condition, Map<String,Object> params);
	/**
	 * get count by full hql query expression
	 * @param queryHql
	 * @param params
	 * @return
	 */
	public long getCountByHql(String queryHql,Map<String,Object> params);

	public List<T> getAll();

	public List<T> getByCondition(String condition, Map<String,Object> params);
	
	public List<T> getPageByHql(int pageNumber, int pageSize, String hql,
			Map<String, Object> params);
	public int getPageCountByHql(int pageSize, String hql,
			Map<String, Object> params);
	
	public Object getUniqueResultByHql(String queryHql,Map<String,Object> params);
	
	public List getResultByHql(String queryHql,Map<String,Object> params);
	
	public PageResult<T> getPageResult(int pageNumber,int pageSize,String condition,Map<String,Object> params);
	
	public SessionFactory getSessionFactory();
    
}